@extends('layouts.appManager')

@section('content')
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-12">
			<div class="text-right mb-2"><a href="/manager/withdraw">提现</a> <a href="/manager/recharge">充值</a> <a href="/manager/profit">记录</a></div>
			<div class="card panel mb-4">
                <div class="card-header">提现(手续费：{{config('conf.userWithdrawRatio')}}%) - 账号余额：{{Auth::user()->remain_money}}积分</div>
                <input type="hidden" value="{{Auth::user()->remain_money}}" class="remain_money">

                <div class="card-body">
                	<form action="/manager/withdrawDo" method="post" onsubmit="return checkForm();">
                		@csrf
	                	<div class="row col-12">
	                		<div class="col-4">
		                		<div class="input-group mt-2">
							        <div class="input-group-prepend">
							          <div class="input-group-text">提现积分</div>
							        </div>
							        <input type="hidden" value="{{config('conf.userWithdrawRatio')}}" class="ratio">
							        <input type="number" class="form-control" id="money" name="money">
						        </div>
		                	</div>

		                	<div class="col-8">
		                		<div class="input-group mt-2">
                                    <input type="text" class="form-control" id="expect_money1" readonly>
                                    <input type="text" class="form-control" id="expect_money2" readonly>
                                    <input type="text" class="form-control" id="expect_money" readonly>
                                    <div class="input-group-append">
                                        <button class="btn btn-info" type="submit">申请提现</button>
                                    </div>
                                </div>
		                	</div>
	                	</div>
					</form>
					<input type="hidden" value="{{config('conf.oneRMBToMoney')}}" id="rate">
                </div>

                <div class="card-body">
                    <form action="/manager/alipaySave" method="post" onsubmit="return checkForm2();">
                        @csrf
                        <div class="row col-12">
                            <div class="col-4"></div>
                            <div class="col-8">
                                <div class="input-group mt-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text">支付宝账号和姓名</div>
                                    </div>
                                    <input type="text" maxlength="20" class="form-control" id="new_alipay_account" name="new_alipay_account" value="{{Auth::user()->alipay_account}}">
                                    <input type="text" maxlength="10" class="form-control" id="new_alipay_name" name="new_alipay_name" value="{{Auth::user()->alipay_name}}">
                                    <div class="input-group-append">
                                        <button class="btn btn-info" type="submit">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <input type="hidden" value="{{Auth::user()->alipay_account}}" id="alipay_account">
                    <input type="hidden" value="{{Auth::user()->alipay_name}}" id="alipay_name">
                </div>
            </div>
        </div>
        @if(!$list->isEmpty())
        <div class="col-12">
        	<h5 class="text-center">提现记录</h5>
        	<table class="table" style="font-size: 13px">
				<thead class="thead-light">
				    <tr>

					    <th scope="col">订单号</th>
						<th scope="col">提现</th>
                        <th scope="col">手续费</th>
                        <th scope="col">实到</th>
{{--					    <th scope="col">本次提现后剩余积分</th>--}}
					    <th scope="col">状态</th>
					    <th scope="col">申请时间</th>
                        <th scope="col">收款账户</th>
				    </tr>
			    </thead>
			    <tbody>
			    	@foreach($list as $item)
					<tr>
						<td>{{$item->order_num}}</td>
						<td>{{$item->money * config('conf.oneRMBToMoney')}} 积分 <br>
                            {{$item->money}} 元
                        </td>
                        <td>
                            {{$item->cash_fee * config('conf.oneRMBToMoney')}} 积分 <br>
                            {{$item->cash_fee}} 元
                        </td>
                        <td>
                            {{$item->real_money * config('conf.oneRMBToMoney')}} 积分 <br>
                            {{$item->real_money}} 元
                        </td>
{{--						<td>{{$item->remain_money}}</td>--}}
						<td>
							@if($item->state == 1)
								已转账
							@else
								待审核
							@endif
						</td>
						<td>{{$item->created_at}}</td>
                        <td>
                            {{$item->alipay_account}}<br>
                            {{$item->alipay_name}}
                        </td>
				    </tr>
				    @endforeach
			    </tbody>
			</table>
			<div class="m-t-20">
		        <ul class="pagination pagination-primary justify-content-center">
		            {{$list->links()}}
		        </ul>
		    </div>
        </div>
        @endif
    </div>
</div>
@endsection
@section('script')
    <script type="text/javascript">
        $('#money').on('keyup change',function(){
            $(this).val($(this).val().replace(/\D|^0/g,''));
            var rate = $('#rate').val();
            var money = $(this).val();
            var ratio = $('.ratio').val();
            var real_money = money / rate;
            var expect_money = real_money*(100 - ratio)/100;
            $('#expect_money').val('实际到账：'+expect_money+'元');
            $('#expect_money1').val('提现金额：'+real_money+'元');
            $('#expect_money2').val('手续费：'+(real_money*ratio/100)+'元');
        });
        function checkForm(){
            var remain_money = $('.remain_money').val();
            remain_money = Math.floor(remain_money);
            var money  = $('#money').val();


            if(remain_money===''||money===''){
                alert('请输入提现金额');
                return false;
            }

            var alipay_account  = $('#alipay_account').val();
            var alipay_name  = $('#alipay_name').val();

            if(alipay_account===''||alipay_name===''){
                alert('支付宝信息不完整');
                return false;
            }

            if (isNaN(money)) {
                alert('请输入数字');
                return false;
            }
            if (money > remain_money) {
                alert('提现金额不能大于您所剩的金额');
                return false;
            }
        }
        function checkForm2(){
            var alipay_account  = $('#new_alipay_account').val();
            var alipay_name  = $('#new_alipay_name').val();

            if(alipay_account===''||alipay_name===''){
                alert('信息不完整');
                return false;
            }
        }
    </script>
@endsection
